package com.heiye.blog.ai.domain.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.heiye.blog.ai.domain.dos.ChatDO;

/**
 * @author: heiye
 * @date: 2025/10/09 下午7:38
 * @version: v1.0.0
 * @description: TODO
 */
public interface ChatMapper extends BaseMapper<ChatDO> {

    /**
     * 分页查询
     *
     * @param current
     * @param size
     * @return
     */
    default Page<ChatDO> selectPageList(Long current, Long size, Long userId) {
        // 分页对象(查询第几页、每页多少数据)
        Page<ChatDO> page = new Page<>(current, size);

        // 构建查询条件
        LambdaQueryWrapper<ChatDO> wrapper = Wrappers.<ChatDO>lambdaQuery()
                .eq(ChatDO::getUserId, userId)
                // 按更新时间倒序
                .orderByDesc(ChatDO::getCreateTime);

        return selectPage(page, wrapper);
    }


    /**
     * 根据用户 ID 和角色 ID 查询
     *
     * @param roleId
     * @return
     */
    default ChatDO selectByUserIdAndRoleId(Long userId, Long roleId) {
        return selectOne(Wrappers.<ChatDO>lambdaQuery()
                .eq(ChatDO::getUserId, userId)
                .eq(ChatDO::getRoleId, roleId));
    }
}
